﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using StockTrader.QuoteCenter.Streamer.DAL;
using StockTrader.QuoteCenter.Streamer.BLL;
using StockTrader.BusinessService.DataContract.HnxInfo;

namespace StockTrader.QuoteCenter.Streamer
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class HnxQuotes : IHttpAsyncHandler
    {
        #region Class Memebers
        private HttpContext oCurrent;
        private string sSessionID = string.Empty;
        #endregion

        public void ProcessRequest(HttpContext context)
        {
            
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        #region IHttpAsyncHandler Members

        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);

            var bInitialized = DBAdapter.Initialized;
            this.oCurrent = context;


            //Get param from the QS
            if (context.Request["sSessionID"] != null)
            {
                this.sSessionID = context.Request["sSessionID"];
            }

            AsyncCallbacksWapper oAsync = new AsyncCallbacksWapper(this.sSessionID)
            {
                AsyncResult = new StockTrader.QuoteCenter.Streamer.BLL.AsyncCore.AsyncResult<List<HnxStockData>>(cb, null),
            };
            ClientManager.Instance.AddCallBack(oAsync);
            return oAsync.AsyncResult;
        }

        public void EndProcessRequest(IAsyncResult result)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
